package com.mvc4g.example.client.view.user;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LazyPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mvc4g.client.Controller;
import com.mvc4g.client.ViewInterface;
import com.mvc4g.example.client.Constants;
import com.mvc4g.example.client.bean.UserBean;

public abstract class AbstractUserView extends LazyPanel implements
		ViewInterface, Constants {

	protected Controller controller = null;

	protected Grid grid = null;
	protected Button button = null;

	@Override
	protected Widget createWidget() {

		Grid grid = new Grid(2, 2);
		grid.setWidget(0, 0, new Label("Last Name:"));
		grid.setWidget(0, 1, getLastName());
		grid.setWidget(1, 0, new Label("First Name:"));
		grid.setWidget(1, 1, getFirstName());

		Button button = new Button(getButtonText());
		button.addClickHandler(new ClickHandler(){

			@Override
			public void onClick(ClickEvent event) {
				buttonAction();				
			}
			
		});

		VerticalPanel mainPanel = new VerticalPanel();
		mainPanel.setPixelSize(300, 100);
		mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		mainPanel.add(grid);
		mainPanel.add(button);
		
		

		return mainPanel;
	}

	@Override
	public void setController(Controller controller) {
		this.controller = controller;
	}
	
	abstract public void init(UserBean user);	
	abstract protected Widget getLastName();
	abstract protected Widget getFirstName();
	abstract protected String getButtonText();
	abstract protected void buttonAction();

}
